﻿package lobby.exchangeddata
{
	/**
	 * ...
	 * @author Doan Nguyen Thuy Nha Truc (Bamboo)
	 */
	import adobe.utils.ProductManager;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import lobby.constants.ConstData;
	import lobby.events.LobbyEvent;
	import lobby.common.Utility;
	import lobby.GlobalVariables;
	public class TransferReportInfo extends EventDispatcher
	{
		public var serverDateFrom:String;
		public var serverDateTo:String
		
		public var pageNum:uint;
		public var addPage:Boolean = true;
		public var dataTransation:Array;
		public var dataDetailTransation:Array;
		public var transId:String;
		
		public function TransferReportInfo()
		{
		
		}
		
		public function resultServerDateTime(result:String):void
		{
			var dateArr:Array = result.split("-");
			var splitDate:String = "/";
			var dateTemp:Date;
			var dayTemp:int;
			if (int(dateArr[3]) < 12)
			{
				dayTemp = int(dateArr[2]);
				dateTemp = new Date(int(dateArr[0]), int(dateArr[1]) - 1, int(dateArr[2]) - 1);
				serverDateFrom = dateTemp.getDate() + splitDate + Utility.getMonthString(dateTemp.getMonth() + 1) + splitDate + dateTemp.getFullYear();
				serverDateTo = dayTemp.toString() + splitDate + Utility.getMonthString(int(dateArr[1])) + splitDate + dateArr[0];				
			}
			else
			{
				dayTemp = int(dateArr[2]);
				dateTemp = new Date(int(dateArr[0]), int(dateArr[1]) - 1, int(dateArr[2]) + 1);
				serverDateFrom = dayTemp.toString() + splitDate + Utility.getMonthString(int(dateArr[1])) + splitDate + dateArr[0];
				serverDateTo = dateTemp.getDate() + splitDate + Utility.getMonthString(dateTemp.getMonth() + 1) + splitDate + dateTemp.getFullYear();
			}
			dispatchEvent(new LobbyEvent(LobbyEvent.UPDATE_DATE_REPORT));
		
		}
		
		public function resultTransferReport(result:String):void
		{
			
			/*var arrReport = sResult.split("&");

			if (arrReport.length<2) {
				_root.movReportDepositWithdraw.pageView_mc._visible = false;
				return;
			}
			var indexRow:Number;

			var totalReport = arrReport[arrReport.length-1].split("*");
			titleHostAmount.text = myHashTable.lookupString("titleHostAmount")+"("+totalReport[0]+")";
			var numColReport = Number(totalReport[1]);
			trace("Tong so dong: "+numColReport);
			var totalDepositReport = totalReport[2];
			var totalWithdrawReport = totalReport[3];*/
			
			
			
			trace("result : " + result);
			dataTransation = new Array();
			var _result:String = result;
			_result = _result.substr(_result.indexOf("_") + 1, _result.length);
			
			
		
			var arrReport:Array = _result.split("&");	
			var _arrRecord:Array = new Array();
			_arrRecord = arrReport[arrReport.length - 1].split("*");
			var totalRecord = _arrRecord[1];
			
			trace("totalRecord : " + totalRecord);
			
			
			if (totalRecord % ConstData.MAX_NUM_ROW_REPORT == 0)
			{
				this.pageNum = totalRecord / ConstData.MAX_NUM_ROW_REPORT;
			}
			else
			{
				this.pageNum = totalRecord / ConstData.MAX_NUM_ROW_REPORT + 1;
			}
			trace("this.pageNum:" + this.pageNum)
			var index:int = 0;
			for (var i:int = 0; i < arrReport.length; i++)
			{
				var transferReportData:Array = new Array();
				transferReportData = arrReport[i].split("*");
				var tranInfo:TransferItemInfo = new TransferItemInfo();									
				
				if(i< (arrReport.length-1)){
					tranInfo.setRow = transferReportData[index];
					tranInfo.setGameSite = transferReportData[index + 1];
					tranInfo.setBet = transferReportData[index + 2];
					tranInfo.setDate = transferReportData[index + 3];
					tranInfo.setHostDeposit = transferReportData[index + 4];
					tranInfo.setHostWithdraw = transferReportData[index + 5];
					tranInfo.setHostBalance = transferReportData[index + 6];
					tranInfo.setGameSiteDeposit = transferReportData[index + 7];
					tranInfo.setGameSiteWithdraw = transferReportData[index + 8];
					tranInfo.setGameSiteBalance = transferReportData[index + 9];
				}else {
					GlobalVariables.totalDeposit = transferReportData[index + 2];
					GlobalVariables.totalWithDraw = transferReportData[index + 2];
					//tranInfo.setTotalDeposit = transferReportData[index + 10];
				}
				/*trace(index + " : " + transferReportData[index] + " : " + transferReportData[index + 1] + " : " + transferReportData[index + 2]
				+ " : " + transferReportData[index + 3] + " : " + transferReportData[index + 4] + " : " + transferReportData[index + 5]
				+ " : " + transferReportData[index + 6] + " : " + transferReportData[index + 7] + " : " + transferReportData[index + 8]
				+ " : " + transferReportData[index + 9]+ " : "+transferReportData[index + 10]);*/
				/*if (String(transactionReportData[index + 11]) == "0")
					tranInfo.setMulti = false;
				else
				{
					tranInfo.setMulti = true;
				}*/
				dataTransation.push(tranInfo);
			}
			
			dispatchEvent(new LobbyEvent(LobbyEvent.UPDATE_TRANSFER_REPORT, true));
		}
	}

}